<?php

namespace app\common\service;


use think\Cache;
use app\model\FreshBanner as BannerModel;
use think\Db;

class Area{


    const AREA = 'are_';

    /**
     * 查询广告详情
     * @param int bannerID
     * @return array
     */
    public static function getAreaById($id){

        $cache = Cache::get(self::AREA.$id);
        if($cache){
            $data = json_decode($cache, true);
            return $data;
        }else{
            $data = Db::name('area')->find($id);
            Cache::set(self::AREA.$id, json_encode($data), 86400*30);
            return $data;
        }
    }


    /**
     * 获取广告列表
     * @praram int place 位置id
     * @return array
     */
    public static function getIndexList($place){
        $key = self::XCX_INDEX_ADV . $place;
        $cache = Cache::store('redis')->get($key);
        if($cache){
            $list = json_decode($cache, true);
        }else{
            $list = Db::name('banner')->where(['status'=>1,'place'=>$place])->select();
            Cache::store('redis')->set($key, json_encode($list), 86400);
        }
        return  $list;
    }




    /**
     * 更新广告信息
     * @param int bannerID
     * @param array data
     * @return array
     */
    public static function updateArea($data, $id){
        $data = Db::name('area')->find($id);
        $data['provinceText'] = Db::name('area')->where('id', $data['province'])->column('name');
        $data['cityText'] = Db::name('area')->where('id', $data['city'])->column('name');
        $data['regionText'] = Db::name('area')->where('id', $data['region'])->column('name');
        $data['streetText'] = Db::name('area')->where('id', $data['street'])->column('name');
        Cache::set(self::AREA.$id, json_encode($data), 86400*30);
    }




    /**
     * 删除商品缓存
     * @param int bannerID 广告ID
     * @return array
     */
    public static function clearCache($bannerID){

    }



    /**
     * 新增用户地址
     * @param int userID 用户ID
     * @param array UserID 用户地址ID
     * @return array
     */
    public static function addUser($userID){

    }


}


?>